package by.koleda.benicetobunnies.model.base;

import org.json.JSONException;
import org.json.JSONObject;

import android.util.Log;

public class BaseModel {
	
	public static final String TAG = BaseModel.class.getSimpleName();

	protected JSONObject jo;

	public BaseModel(JSONObject jsonObject) {
		jo = jsonObject;
	}

	public BaseModel(String jsonString) {
		try {
			jo = new JSONObject(jsonString);
		} catch (JSONException e) {
			Log.w(TAG, e.getMessage());
		}
	}

	public BaseModel() {
		jo = new JSONObject();
	}

	public String getString(String key) {
		if (jo.isNull(key)) {
			return null;
		}
		try {
			return jo.getString(key);
		} catch (Exception e) {
			Log.w(TAG, e.getMessage());
		}
		return null;
	}
	
	public Long getLong(String key) {
		if (jo.isNull(key)) {
			return null;
		}
		try {
			return jo.getLong(key);
		} catch (Exception e) {
			Log.w(TAG, e.getMessage());
		}
		return null;
	}

}
